#ifndef METADATAORGANIZATION_H_
#define METADATAORGANIZATION_H_

#include <iostream>
#include <vector>

#include "Field.h"
#include "Index.h"
#include "OrganizationCommons.h"

class MetadataOrganization
{
protected:
	int handler;
	std::string name;
	int status;
	unsigned int currentField;
	unsigned int currentIndex;
	int idIndexIterator;
	unsigned int currentFieldIndex;
	std::vector<Field> fields;
	std::vector<Index> indexes;
	
	int getMaxField();
	int getMaxIndex();
	void TakeKey(void* reg, int IdField, char* key, unsigned int &size);
	void clear();
public:
	MetadataOrganization();
	MetadataOrganization(const MetadataOrganization &toCopy);
	virtual ~MetadataOrganization();
	
	// Id Methods
	int getHandler();
	void setHandler(int manejador);
	void getName(std::string &nombre);
	void setName(std::string nombre);
	
	// Field methods
	int addField(campo * field);
	void getField(int idField, Field *field);
	void startFieldIterator();
	bool hasNextField();
	void nextField(Field * field);
	
	// Index methods
	int addIndex(campo * fields, std::string &indexName);
	void getIndex(int idIndex, Index *index);
	void dropIndex(int idIndex, std::string &indexName);
	bool isIndex(campo *fields, int &idIndex);
	bool isIndexByID(int idIndex);
	void getIndexName(int idIndex, std::string &indexName);
	
	void startIndexIterator();
	bool hasNextIndex();
	int nextIndex();
	
	void startFieldIndexIterator(int idIndex);
	bool hasNextFieldIndex();
	int nextFieldIndex();
	
	// Record Methods
	void GetKey(void *reg, int idIndex, char * key, unsigned int &size);
	
	// Overloads operator
	const MetadataOrganization &operator=(const MetadataOrganization &toAssign);

	// Persistent Method
	void load();
	void save();
	
};

#endif /*METADATA_H_*/
